package meihua.stopcarapp.presenter;

import android.util.Log;

import java.util.List;

import meihua.mylibrary.baserx.RxSubscriber;
import meihua.stopcarapp.R;
import meihua.stopcarapp.bean.ParkingEntity;
import meihua.stopcarapp.bean.result.LadvanceResult;
import meihua.stopcarapp.bean.result.LockResult;
import meihua.stopcarapp.bean.result.UnLadvanceResult;
import meihua.stopcarapp.bean.result.UserResult;
import meihua.stopcarapp.presenter.contract.ParkingContract;

/**
 * Name: LGZ
 * Time: 2017/5/6.
 * Dec:
 */

public class ParkingPresenter extends ParkingContract.Presenter {

    @Override
    public void sendGetUser(String uid, String phone) {
        mRxManage.add(mModel.getUserById(uid, phone)
                .subscribe(new RxSubscriber<UserResult>(mContext,false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }
                    @Override
                    protected void _onNext(UserResult userEntity) {
                        Log.d("ligaozeng","请求成功");
                        mView.returnUserInfo(userEntity);
                        mView.stopLoading();
                    }
                    @Override
                    protected void _onError(String message) {
                        Log.d("ligaozeng","服务器错误:"+message);
                    }
                }));
    }
    @Override
    public void getParkingListRequest(String longitude, String latitude) {
        mRxManage.add(mModel.getParkingList(longitude,latitude)
                .subscribe(new RxSubscriber<List<ParkingEntity>>(mContext,false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }
                    @Override
                    protected void _onNext(List<ParkingEntity> parkings) {
                        Log.d("ligaozeng","访问服务器");
                        mView.returnParkingList(parkings);
                        mView.stopLoading();
                    }
                    @Override
                    protected void _onError(String message) {
                        Log.d("ligaozeng","服务器错误:"+message);
                    }
                }));
    }

    @Override
    public void getsecdLadvanceRequest(String phone, String parking_list_num) {
        mRxManage.add(mModel.secdLadvance(phone,parking_list_num)
                .subscribe(new RxSubscriber<LadvanceResult>(mContext,false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }
                    @Override
                    protected void _onNext(LadvanceResult result) {
                        Log.d("ligaozeng","访问服务器");
                        mView.returnsecdLadvance(result);
                        mView.stopLoading();
                    }
                    @Override
                    protected void _onError(String message) {
                        Log.d("ligaozeng","服务器错误:"+message);
                    }
                }));
    }

    @Override
    public void getsecdUnLadvanceRequest(String adv_id, String phone, String parking_list_num) {
        mRxManage.add(mModel.secdUnLadvance(adv_id,phone,parking_list_num)
                .subscribe(new RxSubscriber<UnLadvanceResult>(mContext,false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }
                    @Override
                    protected void _onNext(UnLadvanceResult result) {
                        Log.d("ligaozeng","访问服务器");
                        mView.returnsecdUnLadvance(result);
                        mView.stopLoading();
                    }
                    @Override
                    protected void _onError(String message) {
                        Log.d("ligaozeng","服务器错误:"+message);
                    }
                }));
    }

    @Override
    public void getsecdOpenLockRequest(String phone, String parking_list_num) {
        mRxManage.add(mModel.secdOpenLock(phone,parking_list_num)
                .subscribe(new RxSubscriber<LockResult>(mContext,false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }
                    @Override
                    protected void _onNext(LockResult result) {
                        Log.d("ligaozeng","访问服务器");
                        mView.returnOpenLock(result);
                        mView.stopLoading();
                    }
                    @Override
                    protected void _onError(String message) {
                        Log.d("ligaozeng","服务器错误:"+message);
                    }
                }));
    }

}
